package com.handsome.utils;

/**
 * ResultGenerator
 *
 * @author Jiangda
 */
public class ResultGenerator {
    private static final Integer DEFAULT_SUCCESS_CODE = 200;
    private static final Integer DEFAULT_FAIL_CODE = 500;

    private static final String DEFAULT_SUCCESS_MESSAGE = "成功";
    private static final String DEFAULT_FAIL_MESSAGE = "失败";

    public static Result genSuccessResult() {
        Result result = new Result();
        result.setCode(DEFAULT_SUCCESS_CODE);
        result.setMessage(DEFAULT_SUCCESS_MESSAGE);
        return result;
    }

    public static Result<Object> genSuccessResult(Object data) {
        Result<Object> result = new Result<>();
        result.setCode(DEFAULT_SUCCESS_CODE);
        result.setMessage(DEFAULT_SUCCESS_MESSAGE);
        result.setData(data);
        return result;
    }

    public static Result genFailResult(String message) {
        Result result = new Result();
        result.setCode(DEFAULT_FAIL_CODE);
        if (message == null || message.length() < 1) {
            message = DEFAULT_FAIL_MESSAGE;
        }
        result.setMessage(message);
        return result;
    }

}
